//
// Created by 谢祥平 on 22-11-18.
//

#ifndef CARP_TREE_H
#define CARP_TREE_H


#include <head.h>

typedef struct node {
    int data;
    struct node *left, *right;
}Btree;

void preOrdde(Btree *T) {
    if(T != NULL) {
        std::cout << T->data << std::endl;
        preOrdde(T->left);
        preOrdde(T->right);
    }
}

Btree* createtree(Btree** T, int *num, int size, int pos)
{
	if(size == 0)
        return NULL;

    if(pos <= size) {
        (*T) = (Btree*) malloc(sizeof(Btree));
        (*T)->data = num[pos-1];
        (*T)->left = NULL;
        (*T)->right = NULL;
        createtree(&(*T)->left, num, size, pos*2);
        createtree(&(*T)->right, num, size, pos*2+1);
    }

	return (*T);
}


#endif //CARP_TREE_H